home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / Audio / Patchmix / Source / Converter.m < prev    next >
Text File  |  1992-07-31  |  4KB  |  191 lines

  1.  
  2. /* Generated by Interface Builder */
  3.  
  4. #import "Converter.h"
  5. #import "Instrum.h"
  6. #import <appkit/graphics.h>
  7. #import "Statement.h"
  8.  
  9. @implementation Converter
  10.  
  11. + initialize
  12. {
  13.        ocimage = [NXImage findImageNamed:"octcps"];
  14.        opimage = [NXImage findImageNamed:"octpch"];
  15.        cpimage = [NXImage findImageNamed:"cpspch"];
  16.        coimage = [NXImage findImageNamed:"cpsoct"];
  17.        poimage = [NXImage findImageNamed:"pchoct"];
  18.        pcimage = [NXImage findImageNamed:"pchcps"];
  19.     inOffset.x = 30;
  20.     inOffset.y = 28;
  21.     outOffset.x = 30;
  22.     outOffset.y = 6;
  23.     
  24.     return self;
  25. }
  26.  
  27. - init
  28. {
  29.     written = NO;
  30.     size.width = 80.;
  31.     size.height = 80.;
  32.     center.x = size.width/2.;
  33.     center.y = size.height/2.;
  34.     strcpy(type,"Add");
  35.     strcpy(name,"add");
  36.     
  37.     in = [[Param alloc] init:self :&inOffset];
  38.     out = [[Param alloc] init:self :&outOffset];
  39.  
  40.     [in setTitle:"Input:"];
  41.  
  42.     paramList = [[List alloc] initCount:4];
  43.     [paramList addObject:in];
  44.     [paramList addObject:out];
  45.     
  46.     [Inst putUgenInList:self];
  47.     
  48.     return self;
  49. }
  50.  
  51. - remove
  52. {
  53.     id cp,param;
  54.     int i;
  55.                             // make sure not connected first 
  56.     for(i = 0; i < ([paramList count]); i++) {    
  57.         param = [paramList objectAt:i];
  58.         if(cp = [param getConnectedParam]) 
  59.             return 0;
  60.     }
  61.                             // remove ugen from list
  62.     [Inst removeUgenFromList:self];
  63.     return self;
  64. }
  65.  
  66. - (NXImage *)getImage
  67. {                        // get the right image
  68.     return image;
  69. }
  70.  
  71. - move:(NXPoint *)newloc
  72. {
  73.     location = *newloc;
  74.     [in move:&location];
  75.     [out move:&location];
  76.     return self;
  77. }
  78.  
  79. - setCtype:(int)n
  80. {
  81.     switch(n) {
  82.         case 20: {
  83.             image = ocimage;
  84.             strcpy(name,"octcps");
  85.             break;
  86.         }
  87.         case 21: {
  88.             image = opimage;
  89.             strcpy(name,"octpch");
  90.             break;
  91.         }
  92.         case 22: {
  93.             image = cpimage;
  94.             strcpy(name,"cpspch");
  95.             break;
  96.         }
  97.         case 23: {
  98.             image = coimage;
  99.             strcpy(name,"cpsoct");
  100.             break;
  101.         }
  102.         case 24: {
  103.             image = poimage;
  104.             strcpy(name,"pchoct");
  105.             break;
  106.         }
  107.         case 25: {
  108.             image = pcimage;
  109.             strcpy(name,"pchcps");
  110.             break;
  111.         }
  112.     }
  113.     strcpy(type,"Converter");
  114.     return self;
  115. }
  116.  
  117. - findParamAtPoint:(NXPoint *)point
  118. {
  119.     NXRect *rect;
  120.     int i;
  121.     id param;
  122.     
  123.     for(i = 0; i < [paramList count]; i++) {
  124.         param = [paramList objectAt:i];
  125.         rect = [param getRect];
  126.         if(NXMouseInRect(point,rect,NO))
  127.             return param;
  128.     }
  129.     //printf("no param found\n");
  130.     return nil;
  131. }
  132.  
  133. - writeUgen
  134. {
  135.     /*     for each input param:
  136.             see if there is input ugen
  137.                 if so, grab the output (ug?) and multiply it by this
  138.                     param value
  139.                 if not just use the param value
  140.          after all params done, write relevant code into lists
  141.             (declarations, assignments and loop statements)
  142.             i.e. ug? = oscil(,,,,);
  143.         go to output param connected ugen and call its "writeUgen"
  144.     */
  145.     int i;
  146.     int parent[3];
  147.     id param;
  148.     id ug;
  149.     id nupar;
  150.     char str[50];
  151.     
  152.     //printf("writing ugen %d\n",index);
  153.     sprintf(str,"\tfloat ug%d;\n",index);
  154.     [Inst putVarInList:str];
  155.     sprintf(str,"\tfloat in%d;\n",index);
  156.     [Inst putVarInList:str];
  157.  
  158.  
  159.     for(i = 0; i < ([paramList count]-1); i++) {    
  160.         param = [paramList objectAt:i];
  161.         if(nupar = [param getConnectedParam]) {
  162.             ug = [nupar getUgen];
  163.             if([ug getWritten] == NO) { 
  164.                 parent[i] = [[ug writeUgen] getIndex];
  165.             }
  166.             else  {
  167.                 parent[i] = 0;
  168.             }
  169.             //printf("parent[%d] = %d\n",i,parent[i]);
  170.         }
  171.         else 
  172.             parent[i] = 0;
  173.         
  174.     }
  175.     
  176.     sprintf(str,"\tin%d = %.2f;\n",index, 
  177.         atof([[paramList objectAt:0] getValue]));
  178.     [Inst putAssignInList:str];
  179.  
  180.     if(parent[0])
  181.         sprintf(str,"\tug%d = %s(ug%d * in%d) ;\n", index, name, parent[0], index);
  182.     else
  183.         sprintf(str,"\tug%d = %s(in%d);\n", index, name, index, index);
  184.  
  185.     [Inst putAssignInList:str];
  186.     written = YES;
  187.     return self;    
  188. }
  189.  
  190. @end
  191.